package com.allwees.bs.core.model.order.entity;

import com.allwees.bs.core.modelbase.entity.BaseEntity;
import com.allwees.core.common.constant.EPlatform;
import com.allwees.core.common.util.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import java.math.BigDecimal;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@NoArgsConstructor
@MappedSuperclass
public abstract class OrderItemModel extends BaseEntity {
	@Column(length = 48)
	protected String supplierUuid;

	@Column(length = 48)
	protected String retailerUuid;

	@Column(length = 48)
	protected String storeUuid;

	@Column(name = "order_uuid", updatable = false, length = 48)
	protected String orderUuid;

	@Column(updatable = false, length = 48)
	protected String orderNo;

	@Column(length = 48, updatable = false)
	private String inviterUserUuid;

	@Column(length = 48)
	protected String userUuid;

	// 商品ID
	@Column(name = "product_uuid", length = 48)
	protected String productUuid;

	// 商品SKU ID
	@Column(name = "sku_uuid", length = 48)
	protected String skuUuid;

	// 购买数量
	protected Integer quantity;

	// 商品单价
	protected BigDecimal price;

	protected BigDecimal priceAdjust;


	/** 商品快递单价 **/
	protected BigDecimal shippingPrice;

	/** 加价后运费 **/
	protected BigDecimal shippingPriceAdjust;

	// 订单sku总金额
	protected BigDecimal amt;

	// Sku总价
	protected BigDecimal amtSku;


	// Sku总价
	protected BigDecimal amtSaleTax;

	// 原始 Sku
	protected BigDecimal originalAmtSku;

	protected BigDecimal originalAmt;

	protected BigDecimal originalAmtShipping;

	// 运费
	protected BigDecimal amtShipping;

	//cash 实付金额
	protected BigDecimal amtCashSku;

	//cash 实付商品金额
	private BigDecimal amtCashProductSku = BigDecimal.ZERO;

	//cash 实付运费金额
	private BigDecimal amtCashShippingSku = BigDecimal.ZERO;

	// 商品优惠金额
	protected BigDecimal amtSkuCoupon;

	/**
	 * sku商品优惠
	 */
	protected BigDecimal amtProductDiscountSku;

	/**
	 * sku运费优惠
	 */
	private BigDecimal amtShippingDiscountSku;


	/** 原始单价 **/
	protected BigDecimal originalPrice;


	/** 商家应收sku金额 */
	protected BigDecimal merchantAmtSku ;

	/** 加价后的sku运费 **/
	protected BigDecimal shippingAmtSkuAfterAdd;

	/** 加价后的sku商品金额 **/
	protected BigDecimal productAmtSkuAfterAdd;


	/** 平台应收sku金额  **/
	protected BigDecimal platformAmtSku;

	/** sku原始运费 **/
	protected BigDecimal originalAmtShippingSku;

	/** sku原始税费 **/
	protected BigDecimal originalAmtSaleTaxSku;

	/** sku加价后税费 **/
	private BigDecimal amtSaleTaxSkuAfterAdd;

	/** sku 供应价 **/
	protected BigDecimal supplyPrice;

	/** 运单号 */
	@Column(length = 32)
	protected String expressCode;

	//
	protected String shippingStatus;

	/** 支付日期 **/
	protected Date paymentAt;

	/** 发货日期 **/
	protected Date shippingAt;

	protected Date deliverAt;

	/** 可发货日期 **/
	protected Date canShippingAt;

	/** 评论时间 **/
	protected Date reviewAt;

	// 申请退货时间
	protected Date applyRefundAt;

	// 退货时间
	protected Date refundAt;

	/** 是否已退货 **/
	protected Boolean refunded;

	/** 是否已取消 */
	protected Boolean canceled;

    /**
     * 是否是新用户购买
     */
    protected Boolean newUser;

	/**
	 * 物流公司uuid
	 */
	protected String logisticsUuid;

	/**
	 * 创建订单时的来源平台
	 */
    @Enumerated(EnumType.STRING)
	protected EPlatform platform;

	/**
	 * 退款渠道号
	 */
	@Column(name = "refund_channel_uuid", updatable = false, length = 48)
	private String refundChannelUuid;

	public boolean getCanShipping(){
		return canShippingAt != null && canShippingAt.getTime() < DateUtil.nowTime();
	}
}
